<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
    margin: 0;
    padding: 0;
}
.wrap{
    width: 800px;
    margin: 100px auto 0;
}
h1{
    text-align: center;
    margin-bottom: 20px;
}
table{
    border: 1px solid lightblue;
    border-collapse: collapse;
    width: 100%;
}
table tr{
    border: 1px solid lightblue;
    width: 100%;
}
table th{
    border: 1px solid lightblue;
    padding: 8px 0;
}
table td{
    border: 1px solid lightblue;
    padding: 8px 0;
}
</style>
</head>
<body>
    
<div class="wrap">
    <h1>用户信息</h1>
    <table>
        <!-- <tr>
            <th>账号</th>
            <th>昵称</th>
            <th>性别</th>
            <th>年龄</th>
            <th>邮箱</th>
        </tr>
        <tr>
            <td>xiaocuo</td>
            <td>小错</td>
            <td>男</td>
            <td>23</td>
            <td>2239222721@qq.com</td>
        </tr> -->
    </table>
</div>

<script src="./utils.js"></script>
<script>

let table = document.querySelector('table')

// 发送ajax请求获取用户数据
ajax({
    type: 'get',
    url: 'http://localhost:8080/users/list',
    dataType: 'json'
})
.then((arr)=>{
    let tmp = `<tr>
                <th>账号</th>
                <th>昵称</th>
                <th>性别</th>
                <th>年龄</th>
                <th>邮箱</th>
            </tr>`
    arr.forEach((item)=>{
        tmp += `<tr>
                    <td>${item.user}</td>
                    <td>${item.nickname}</td>
                    <td>${item.sex}</td>
                    <td>${item.age}</td>
                    <td>${item.email}</td>
                </tr>`
    })
    table.innerHTML = tmp
})

</script>
</body>
</html>